package com.fubowen.reader.adapter

import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder


class SwipeDeleteCallback(private val ratio: Float = 0.5f, val delete: (ViewHolder) -> Unit) : ItemTouchHelper.Callback() {

    override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: ViewHolder) = makeMovementFlags(0, ItemTouchHelper.LEFT)

    override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder, target: ViewHolder) = false

    override fun getSwipeThreshold(viewHolder: ViewHolder) = ratio

    override fun getSwipeEscapeVelocity(defaultValue: Float) = Float.MAX_VALUE

    override fun onSwiped(viewHolder: ViewHolder, direction: Int) = delete(viewHolder)
}